<%@page import="ll.sms.util.*"%><%@ page language="java"
	import="ll.sms.pojo.*,ll.sms.web.*"
	pageEncoding="UTF-8"%>
<%@page import="org.apache.commons.lang.StringUtils"%>
<%@page import="ll.sms.db.Transaction"%>
<%@page import="ll.sms.factory.BeanFactory"%>
<%@page import="ll.sms.dao.SmsUserDAO"%>
<%
	try {
		SmsUser smsUser = new SmsUser();
		RequestUtils.populate(smsUser, request);
		String newapwd = request.getParameter("pwd");
		String pass_cfrm = request.getParameter("npwd");
		String userid = request.getParameter("userid");
		String flag = request.getParameter("flag");

			//修改用户密码
		if("changepassword".equals(flag) && !StringUtils.isBlank(userid)){
		if (!StringUtils.isBlank(newapwd)
			&& newapwd.equals(pass_cfrm)) {
			out.print(WebBusinessImpl.getInstance().updateUserPassword(newapwd,userid));
			return;
		}
		}

		if(!SmsUtil.checkUsername(smsUser.getUuname())){
		out.print( "{success:false,errors:{msg:'用户名允许的字符为:英文字母、中文、下划线,长度为4-32位'}}");
		return;
		}


		String requestDefaultChannelId =  ParamUtils.getParameter(request,"uchannel_1");
		
			Transaction.begin();
			SmsUser realUser = ((SmsUserDAO)BeanFactory.getBean(SmsUserDAO.class)).findUserByIdOrUname("uids",smsUser.getUids());
			Transaction.commit();
		if(StringUtils.isBlank(requestDefaultChannelId)){
			//若通道ID为空，即就是表示使用默认
			smsUser.setUchannel(realUser.getUchannel());
		}else{
			smsUser.setUchannel(requestDefaultChannelId);
		}
		//代理不允许该
		smsUser.setUcompany(realUser.getUcompany());
		//余额不允许改
		smsUser.setUsmsnum(realUser.getUsmsnum());
		out.print(WebBusinessImpl.getInstance().updateUser (smsUser));

		} catch (Exception e) {
			e.printStackTrace();
			out.print("{success:false,errors:{msg:'修改失败！！'}}");
		}
%>
